package com.kalix.middleware.payment.biz.utils;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.kalix.middleware.payment.api.model.AlipayConfig;
import com.kalix.middleware.payment.api.utils.AlipayUtils;

public class AlipayAPIFactory {
    /** API调用客户端 */
    private static AlipayClient alipayClient;
    /** 支付宝基本配置 */
    private static AlipayConfig alipayConfig;
    /**
     * 获得API调用客户端
     */
    public static AlipayClient getAlipayClient() {
        alipayConfig = AlipayUtils.getAlipayConfig();
        if(null == alipayClient){
            alipayClient = new DefaultAlipayClient(
                    alipayConfig.getAlipay_gateway(),
                    alipayConfig.getApp_id(),
                    alipayConfig.getPrivate_key(),
                    "json",
                    alipayConfig.getCharset(),
                    alipayConfig.getAlipay_public_key(),
                    alipayConfig.getSign_type()
            );
        }
        return alipayClient;
    }

}
